WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 998c131

Browse files
committed
fixed search organization getting rate limited
1 parent 1f9f7bb commit 998c131

File tree

3 files changed

+141
-17
lines changed

3 files changed

+141
-17
lines changed

docs/docs/auto-docs/screens/OrgList/OrgList/functions/default.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
> **default**(): `Element`
88
9-
Defined in: [src/screens/OrgList/OrgList.tsx:104](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/screens/OrgList/OrgList.tsx#L104)
9+
Defined in: [src/screens/OrgList/OrgList.tsx:107](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/screens/OrgList/OrgList.tsx#L107)
1010

1111
## Returns
1212

src/screens/OrgList/OrgList.spec.tsx

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { StaticMockLink } from 'utils/StaticMockLink';
1919
import i18nForTest from 'utils/i18nForTest';
2020
import OrgList from './OrgList';
2121
import { MOCKS, MOCKS_ADMIN, MOCKS_EMPTY } from './OrgListMocks';
22-
import { ORGANIZATION_LIST, CURRENT_USER } from 'GraphQl/Queries/Queries';
22+
import {
23+
ORGANIZATION_FILTER_LIST,
24+
CURRENT_USER,
25+
} from 'GraphQl/Queries/Queries';
2326
import { GET_USER_NOTIFICATIONS } from 'GraphQl/Queries/NotificationQueries';
2427
import useLocalStorage from 'utils/useLocalstorage';
2528
import { vi } from 'vitest';
@@ -122,7 +125,7 @@ const renderWithMocks = (mocks: MockedResponse[]) => {
122125
const createOrgMock = (organizations: unknown[]) => {
123126
const orgListMock = {
124127
request: {
125-
query: ORGANIZATION_LIST,
128+
query: ORGANIZATION_FILTER_LIST,
126129
variables: { filter: '' },
127130
},
128131
result: {
@@ -134,7 +137,7 @@ const createOrgMock = (organizations: unknown[]) => {
134137

135138
// Filter out any ORGANIZATION_LIST mocks from MOCKS to avoid conflicts
136139
const mocksWithoutOrgList = MOCKS.filter(
137-
(mock) => mock.request.query !== ORGANIZATION_LIST,
140+
(mock) => mock.request.query !== ORGANIZATION_FILTER_LIST,
138141
);
139142

140143
return [orgListMock, ...mocksWithoutOrgList];
@@ -402,7 +405,7 @@ const mockConfigurations = {
402405
...MOCKS,
403406
{
404407
request: {
405-
query: ORGANIZATION_LIST,
408+
query: ORGANIZATION_FILTER_LIST,
406409
variables: { filter: '' },
407410
},
408411
result: {
@@ -413,7 +416,7 @@ const mockConfigurations = {
413416
},
414417
{
415418
request: {
416-
query: ORGANIZATION_LIST,
419+
query: ORGANIZATION_FILTER_LIST,
417420
variables: { filter: 'Dog' },
418421
},
419422
result: {
@@ -487,7 +490,7 @@ const mockConfigurations = {
487490
},
488491
{
489492
request: {
490-
query: ORGANIZATION_LIST,
493+
query: ORGANIZATION_FILTER_LIST,
491494
variables: { filter: '' },
492495
},
493496
result: {
@@ -501,7 +504,7 @@ const mockConfigurations = {
501504
...MOCKS,
502505
{
503506
request: {
504-
query: ORGANIZATION_LIST,
507+
query: ORGANIZATION_FILTER_LIST,
505508
variables: { filter: '' },
506509
},
507510
result: {
@@ -881,7 +884,7 @@ describe('Advanced Component Functionality Tests', () => {
881884
...MOCKS,
882885
{
883886
request: {
884-
query: ORGANIZATION_LIST,
887+
query: ORGANIZATION_FILTER_LIST,
885888
variables: { filter: '' },
886889
},
887890
result: {
@@ -1225,7 +1228,7 @@ describe('Advanced Component Functionality Tests', () => {
12251228
...MOCKS,
12261229
{
12271230
request: {
1228-
query: ORGANIZATION_LIST,
1231+
query: ORGANIZATION_FILTER_LIST,
12291232
variables: { filter: '' },
12301233
},
12311234
result: {
@@ -1319,7 +1322,7 @@ describe('Advanced Component Functionality Tests', () => {
13191322
...MOCKS,
13201323
{
13211324
request: {
1322-
query: ORGANIZATION_LIST,
1325+
query: ORGANIZATION_FILTER_LIST,
13231326
variables: { filter: '' },
13241327
},
13251328
result: {
@@ -1330,7 +1333,7 @@ describe('Advanced Component Functionality Tests', () => {
13301333
},
13311334
{
13321335
request: {
1333-
query: ORGANIZATION_LIST,
1336+
query: ORGANIZATION_FILTER_LIST,
13341337
variables: { filter: 'NonexistentOrg' },
13351338
},
13361339
result: {
@@ -1511,7 +1514,7 @@ describe('Advanced Component Functionality Tests', () => {
15111514
const errorMocks = [
15121515
{
15131516
request: {
1514-
query: ORGANIZATION_LIST,
1517+
query: ORGANIZATION_FILTER_LIST,
15151518
variables: {
15161519
id: '123',
15171520
filter: '',
@@ -1626,7 +1629,7 @@ describe('Advanced Component Functionality Tests', () => {
16261629
},
16271630
{
16281631
request: {
1629-
query: ORGANIZATION_LIST,
1632+
query: ORGANIZATION_FILTER_LIST,
16301633
variables: { filter: '' },
16311634
},
16321635
result: {
@@ -1727,7 +1730,7 @@ describe('Advanced Component Functionality Tests', () => {
17271730
},
17281731
{
17291732
request: {
1730-
query: ORGANIZATION_LIST,
1733+
query: ORGANIZATION_FILTER_LIST,
17311734
variables: { filter: '' },
17321735
},
17331736
result: {
@@ -2129,4 +2132,122 @@ describe('Advanced Component Functionality Tests', () => {
21292132
// If modal doesn't appear, test still passes
21302133
}
21312134
});
2135+
2136+
test('Testing organization creation when CREATE_ORGANIZATION_MUTATION returns null data', async () => {
2137+
setItem('id', '123');
2138+
setItem('role', 'administrator');
2139+
2140+
// Mock with null data response
2141+
const mockWithNullData = [
2142+
...MOCKS,
2143+
{
2144+
request: {
2145+
query: ORGANIZATION_FILTER_LIST,
2146+
variables: { filter: '' },
2147+
},
2148+
result: {
2149+
data: {
2150+
organizations: mockOrgData.singleOrg,
2151+
},
2152+
},
2153+
},
2154+
{
2155+
request: {
2156+
query: CREATE_ORGANIZATION_MUTATION_PG,
2157+
variables: {
2158+
name: 'Test Organization',
2159+
description: 'Test Description',
2160+
addressLine1: '123 Test St',
2161+
addressLine2: '',
2162+
city: 'Test City',
2163+
countryCode: 'af',
2164+
postalCode: '12345',
2165+
state: 'Test State',
2166+
avatar: null,
2167+
},
2168+
},
2169+
result: {
2170+
data: null,
2171+
},
2172+
},
2173+
{
2174+
request: {
2175+
query: CREATE_ORGANIZATION_MEMBERSHIP_MUTATION_PG,
2176+
variables: {
2177+
memberId: '123',
2178+
organizationId: undefined,
2179+
role: 'administrator',
2180+
},
2181+
},
2182+
result: {
2183+
data: {
2184+
createOrganizationMembership: {
2185+
id: 'membership-id',
2186+
},
2187+
},
2188+
},
2189+
},
2190+
];
2191+
2192+
render(
2193+
<MockedProvider mocks={mockWithNullData}>
2194+
<BrowserRouter>
2195+
<Provider store={store}>
2196+
<I18nextProvider i18n={i18nForTest}>
2197+
<ThemeProvider theme={createTheme()}>
2198+
<OrgList />
2199+
</ThemeProvider>
2200+
</I18nextProvider>
2201+
</Provider>
2202+
</BrowserRouter>
2203+
</MockedProvider>,
2204+
);
2205+
2206+
await wait();
2207+
2208+
// Open organization creation modal
2209+
await userEvent.click(screen.getByTestId('createOrganizationBtn'));
2210+
2211+
// Fill form
2212+
await userEvent.type(
2213+
screen.getByTestId('modalOrganizationName'),
2214+
'Test Organization',
2215+
);
2216+
await userEvent.type(
2217+
screen.getByTestId('modalOrganizationDescription'),
2218+
'Test Description',
2219+
);
2220+
await userEvent.type(
2221+
screen.getByTestId('modalOrganizationAddressLine1'),
2222+
'123 Test St',
2223+
);
2224+
await userEvent.type(
2225+
screen.getByTestId('modalOrganizationCity'),
2226+
'Test City',
2227+
);
2228+
await userEvent.type(
2229+
screen.getByTestId('modalOrganizationState'),
2230+
'Test State',
2231+
);
2232+
await userEvent.type(
2233+
screen.getByTestId('modalOrganizationPostalCode'),
2234+
'12345',
2235+
);
2236+
await userEvent.selectOptions(
2237+
screen.getByTestId('modalOrganizationCountryCode'),
2238+
'Afghanistan',
2239+
);
2240+
2241+
// Submit form
2242+
await userEvent.click(screen.getByTestId('submitOrganizationForm'));
2243+
2244+
// Wait for form submission to complete
2245+
await wait();
2246+
2247+
// Verify that toast.success was NOT called since data is null
2248+
expect(mockToast.success).not.toHaveBeenCalled();
2249+
2250+
// Verify that the modal should still be open since the success path wasn't taken
2251+
expect(screen.getByTestId('modalOrganizationHeader')).toBeInTheDocument();
2252+
});
21322253
});

src/screens/OrgList/OrgList.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ import {
5050
CREATE_ORGANIZATION_MUTATION_PG,
5151
CREATE_ORGANIZATION_MEMBERSHIP_MUTATION_PG,
5252
} from 'GraphQl/Mutations/mutations';
53-
import { ORGANIZATION_LIST, CURRENT_USER } from 'GraphQl/Queries/Queries';
53+
import {
54+
CURRENT_USER,
55+
ORGANIZATION_FILTER_LIST,
56+
} from 'GraphQl/Queries/Queries';
5457

5558
import PaginationList from 'components/Pagination/PaginationList/PaginationList';
5659
import { useTranslation } from 'react-i18next';
@@ -176,7 +179,7 @@ function orgList(): JSX.Element {
176179
data: allOrganizationsData,
177180
loading: loadingAll,
178181
refetch: refetchOrgs,
179-
} = useQuery(ORGANIZATION_LIST, {
182+
} = useQuery(ORGANIZATION_FILTER_LIST, {
180183
variables: { filter: filterName },
181184
fetchPolicy: 'network-only',
182185
errorPolicy: 'all',

0 commit comments

Comments
 (0)