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

include nested location ids in client search #917

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ Object {
title="All Locations"
value=""
/>
<TreeNode
title="CSB Hopital Bouficha"
value="e2b4a441-21b5-4d03-816b-09d45b17cad7"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: why did this change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the correct behavior, no location selected at render

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if am wrong, looks like this is not a snapshot of the options after a select, but a general snapshot of the options that exist in this particular treeSelect, during first render there should be 2 options the All locations and root location, as shown here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2022-01-27 15-53-16
Only one label until you click the dropdown

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it back, the tests failed. I think it's a disconnect between the CI and local setup. Ought to be checked out

</TreeSelect>
</FormItem>
<FormItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,32 @@ export const locationHierarchy = {
},
},
},
parentChildren: {},
parentChildren: {
'70589012-899c-401d-85a1-13fabce26aab': [
'325b9549-80fa-4dd0-9cf8-f0538cbebb18',
'e2b4a441-21b5-4d03-816b-09d45b17cad7',
'72f8ae88-58c9-40b4-863a-1c7bc6549a8b',
'52c10f07-6653-470d-9fee-14b0bb111c2a',
'd309898b-3925-494f-a30c-689222d3fcce',
'dbacb5dc-c8a3-439d-b407-13ffd570b9ef',
'27400130-8127-4f54-b14f-e26f20ecae14',
'14e83edc-5a54-44f5-816e-c96c61b5d911',
'9c183088-e498-4183-af41-b29bd32d94b6',
'66c88197-8281-4eb4-ae2e-4a89ae8419ed',
],
'e447d5bb-8d42-4be4-b91d-b8d185cf81a6': ['1018b255-0889-492c-b5dd-31a50cb3db4d'],
'e5631d3e-70c3-4083-ac17-46f9467c6dd5': ['5d99a60e-126e-4c40-b5ce-439f920de090'],
'7a663f5e-2619-4a2d-a7df-7250263f47d2': ['9a0e7727-b011-458f-832a-61108b2fe381'],
'18b3841b-b5b1-4971-93d0-d36ac20c4565': ['70589012-899c-401d-85a1-13fabce26aab'],
'fee237ef-75e8-4ada-b15f-6d1a92633f33': ['e5631d3e-70c3-4083-ac17-46f9467c6dd5'],
'16c58ef5-3b19-4ec2-ba9c-aefac3d08a66': ['e447d5bb-8d42-4be4-b91d-b8d185cf81a6'],
'ede2c7cf-331e-497e-9c7f-2f914d734604': [
'18b3841b-b5b1-4971-93d0-d36ac20c4565',
'fee237ef-75e8-4ada-b15f-6d1a92633f33',
'16c58ef5-3b19-4ec2-ba9c-aefac3d08a66',
'7a663f5e-2619-4a2d-a7df-7250263f47d2',
],
},
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ describe('components/DownloadClientData', () => {
it('downloads csv correctly', async () => {
fetch.mockOnce(JSON.stringify(fixtures.sampleTeamAssignment));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

const queryClient = new QueryClient();
Expand Down Expand Up @@ -276,7 +277,8 @@ describe('components/DownloadClientData', () => {
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/security/authenticate',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7?is_jurisdiction=true',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
]);
expect(papaparseMock).toBeCalledWith([fixtures.child1CsvEntry, fixtures.child2CsvEntry], {
header: true,
Expand All @@ -290,6 +292,7 @@ describe('components/DownloadClientData', () => {
it('submits if card status is not entered', async () => {
fetch.mockOnce(JSON.stringify(fixtures.sampleTeamAssignment));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

const queryClient = new QueryClient();
Expand Down Expand Up @@ -329,7 +332,8 @@ describe('components/DownloadClientData', () => {
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/security/authenticate',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7?is_jurisdiction=true',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7',
]);
expect(papaparseMock).toBeCalledWith([fixtures.child1CsvEntry, fixtures.child2CsvEntry], {
header: true,
Expand All @@ -339,6 +343,7 @@ describe('components/DownloadClientData', () => {
it('uses the default location id if location not selected', async () => {
fetch.mockOnce(JSON.stringify(fixtures.sampleTeamAssignment));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

const queryClient = new QueryClient();
Expand Down Expand Up @@ -377,7 +382,8 @@ describe('components/DownloadClientData', () => {
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/security/authenticate',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7?is_jurisdiction=true',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
]);
expect(papaparseMock).toBeCalledWith([fixtures.child1CsvEntry, fixtures.child2CsvEntry], {
header: true,
Expand All @@ -386,8 +392,7 @@ describe('components/DownloadClientData', () => {

it('handles fetch error when fetching user data - team assignments', async () => {
fetch.mockRejectOnce(() => Promise.reject('API is down'));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockOnce(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

const notificationErrorMock = jest.spyOn(notifications, 'sendErrorNotification');

// turn retries off - makes fetch fail on first try
Expand Down Expand Up @@ -422,7 +427,7 @@ describe('components/DownloadClientData', () => {
it('handles fetch error when fetching user location hierarchy', async () => {
fetch.mockOnce(JSON.stringify(fixtures.sampleTeamAssignment));
fetch.mockRejectOnce(() => Promise.reject('API is down'));
fetch.mockOnce(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

const notificationErrorMock = jest.spyOn(notifications, 'sendErrorNotification');

// turn retries off - makes fetch fail on first try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('components/DownloadClientData/utils/submitForm', () => {
const setSubmittingMock = jest.fn();

it('submits the form correctly', async () => {
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockResponse(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

submitForm(
Expand All @@ -161,16 +162,9 @@ describe('components/DownloadClientData/utils/submitForm', () => {
});

expect(setSubmittingMock.mock.calls[0][0]).toEqual(true);
expect(fetch.mock.calls[0]).toEqual([
`https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=${clientLocation}&attribute=card_status:${cardStatus}`,
{
headers: {
accept: 'application/json',
authorization: 'Bearer hunter2',
'content-type': 'application/json;charset=UTF-8',
},
method: 'GET',
},
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
]);

expect(setSubmittingMock.mock.calls[1][0]).toEqual(false);
Expand All @@ -183,8 +177,37 @@ describe('components/DownloadClientData/utils/submitForm', () => {
);
});

it('handles error if fetching Nested Location Ids fails', async () => {
fetch.mockReject(() => Promise.reject('API is down'));
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));

const notificationErrorMock = jest.spyOn(notifications, 'sendErrorNotification');

submitForm(
values,
accessToken,
opensrpBaseURL,
OpenSRPService,
fixtures.locations,
setSubmittingMock
);
await act(async () => {
await flushPromises();
});
expect(setSubmittingMock.mock.calls[0][0]).toEqual(true);
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
]);
expect(setSubmittingMock.mock.calls[1][0]).toEqual(false);
expect(papaparseMock).not.toHaveBeenCalled();
expect(notificationErrorMock).toHaveBeenCalledWith(lang.ERROR_OCCURRED);
});

it('handles error if submission fails', async () => {
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockReject(() => Promise.reject('API is down'));

const notificationErrorMock = jest.spyOn(notifications, 'sendErrorNotification');

submitForm(
Expand All @@ -199,23 +222,17 @@ describe('components/DownloadClientData/utils/submitForm', () => {
await flushPromises();
});
expect(setSubmittingMock.mock.calls[0][0]).toEqual(true);
expect(fetch.mock.calls[0]).toEqual([
`https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=${clientLocation}&attribute=card_status:${cardStatus}`,
{
headers: {
accept: 'application/json',
authorization: 'Bearer hunter2',
'content-type': 'application/json;charset=UTF-8',
},
method: 'GET',
},
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7&attribute=card_status:needs_card',
]);
expect(setSubmittingMock.mock.calls[1][0]).toEqual(false);
expect(papaparseMock).not.toHaveBeenCalled();
expect(notificationErrorMock).toHaveBeenCalledWith(lang.ERROR_OCCURRED);
});

it('calls API correctly if card status is empty', async () => {
fetch.mockOnce(JSON.stringify(fixtures.locationHierarchy));
fetch.mockResponse(JSON.stringify([fixtures.mother, fixtures.child1, fixtures.child2]));

submitForm(
Expand All @@ -233,16 +250,9 @@ describe('components/DownloadClientData/utils/submitForm', () => {
await flushPromises();
});
expect(setSubmittingMock.mock.calls[0][0]).toEqual(true);
expect(fetch.mock.calls[0]).toEqual([
`https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=${clientLocation}`,
{
headers: {
accept: 'application/json',
authorization: 'Bearer hunter2',
'content-type': 'application/json;charset=UTF-8',
},
method: 'GET',
},
expect(fetch.mock.calls.map((res) => res[0])).toEqual([
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/location/hierarchy/e2b4a441-21b5-4d03-816b-09d45b17cad7',
'https://unicef-tunisia-stage.smartregister.org/opensrp/rest/client/search?locationIds=325b9549-80fa-4dd0-9cf8-f0538cbebb18,e2b4a441-21b5-4d03-816b-09d45b17cad7,72f8ae88-58c9-40b4-863a-1c7bc6549a8b,52c10f07-6653-470d-9fee-14b0bb111c2a,d309898b-3925-494f-a30c-689222d3fcce,dbacb5dc-c8a3-439d-b407-13ffd570b9ef,27400130-8127-4f54-b14f-e26f20ecae14,14e83edc-5a54-44f5-816e-c96c61b5d911,9c183088-e498-4183-af41-b29bd32d94b6,66c88197-8281-4eb4-ae2e-4a89ae8419ed,1018b255-0889-492c-b5dd-31a50cb3db4d,5d99a60e-126e-4c40-b5ce-439f920de090,9a0e7727-b011-458f-832a-61108b2fe381,70589012-899c-401d-85a1-13fabce26aab,e5631d3e-70c3-4083-ac17-46f9467c6dd5,e447d5bb-8d42-4be4-b91d-b8d185cf81a6,18b3841b-b5b1-4971-93d0-d36ac20c4565,fee237ef-75e8-4ada-b15f-6d1a92633f33,16c58ef5-3b19-4ec2-ba9c-aefac3d08a66,7a663f5e-2619-4a2d-a7df-7250263f47d2,e2b4a441-21b5-4d03-816b-09d45b17cad7',
]);
expect(setSubmittingMock.mock.calls[1][0]).toEqual(false);
expect(papaparseMock).toBeCalledWith([fixtures.child1CsvEntry, fixtures.child2CsvEntry], {
Expand Down
Loading