diff --git a/src/GraphQl/Queries/Queries.ts b/src/GraphQl/Queries/Queries.ts index 93f40f9e40..ab2e8aaa10 100644 --- a/src/GraphQl/Queries/Queries.ts +++ b/src/GraphQl/Queries/Queries.ts @@ -335,6 +335,62 @@ export const EVENT_FEEDBACKS = gql` } `; +// Query to take the Organization with data +export const ORGANIZATIONS_LIST_BY_CREATOR_ID = gql` + query OrganizationsByCreator($creatorId: ID!) { + organizations(where: { creatorId: $creatorId }) { + _id + image + creator { + firstName + lastName + email + } + name + description + address { + city + countryCode + dependentLocality + line1 + line2 + postalCode + sortingCode + state + } + userRegistrationRequired + visibleInSearch + members { + _id + firstName + lastName + email + } + admins { + _id + firstName + lastName + email + createdAt + } + membershipRequests { + _id + user { + firstName + lastName + email + } + } + blockedUsers { + _id + firstName + lastName + email + } + } + } +`; + // Query to take the Organization with data export const ORGANIZATIONS_LIST = gql` query Organizations($id: ID!) { diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx index 2a0ef3815d..6e01bfc9e6 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx @@ -1,5 +1,5 @@ import React, { act } from 'react'; -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import 'jest-localstorage-mock'; import { I18nextProvider } from 'react-i18next'; @@ -11,7 +11,7 @@ import LeftDrawerOrg from './LeftDrawerOrg'; import { Provider } from 'react-redux'; import { MockedProvider } from '@apollo/react-testing'; import { store } from 'state/store'; -import { ORGANIZATIONS_LIST } from 'GraphQl/Queries/Queries'; +import { ORGANIZATIONS_LIST_BY_CREATOR_ID } from 'GraphQl/Queries/Queries'; import { StaticMockLink } from 'utils/StaticMockLink'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; import useLocalStorage from 'utils/useLocalstorage'; @@ -77,7 +77,7 @@ const MOCKS = [ }, { request: { - query: ORGANIZATIONS_LIST, + query: ORGANIZATIONS_LIST_BY_CREATOR_ID, variables: { id: '123' }, }, result: { @@ -140,7 +140,7 @@ const MOCKS = [ const MOCKS_WITH_IMAGE = [ { request: { - query: ORGANIZATIONS_LIST, + query: ORGANIZATIONS_LIST_BY_CREATOR_ID, variables: { id: '123' }, }, result: { @@ -204,7 +204,7 @@ const MOCKS_WITH_IMAGE = [ const MOCKS_EMPTY = [ { request: { - query: ORGANIZATIONS_LIST, + query: ORGANIZATIONS_LIST_BY_CREATOR_ID, variables: { id: '123' }, }, result: { @@ -304,8 +304,9 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { , ); - await wait(); - expect(screen.getByTestId(/orgBtn/i)).toBeInTheDocument(); + await waitFor(() => + expect(screen.getByTestId(/orgBtn/i)).toBeInTheDocument(), + ); }); test('Testing Menu Buttons', async () => { @@ -390,7 +391,7 @@ describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { ); await wait(); expect( - screen.getByText(/Error occured while loading Organization data/i), + screen.getByText(/Error Occured while loading the Organization/i), ).toBeInTheDocument(); }); diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx index 3a3ba378cf..21d5a46e6c 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.tsx @@ -1,6 +1,6 @@ import { useQuery } from '@apollo/client'; import { WarningAmberOutlined } from '@mui/icons-material'; -import { ORGANIZATIONS_LIST } from 'GraphQl/Queries/Queries'; +import { ORGANIZATIONS_LIST_BY_CREATOR_ID } from 'GraphQl/Queries/Queries'; import CollapsibleDropdown from 'components/CollapsibleDropdown/CollapsibleDropdown'; import IconComponent from 'components/IconComponent/IconComponent'; import React, { useEffect, useState } from 'react'; @@ -50,8 +50,8 @@ const leftDrawerOrg = ({ | { organizations: InterfaceQueryOrganizationsListObject[] } | undefined; loading: boolean; - } = useQuery(ORGANIZATIONS_LIST, { - variables: { id: orgId }, + } = useQuery(ORGANIZATIONS_LIST_BY_CREATOR_ID, { + variables: { creatorId: orgId }, }); // Set organization data when query data is available @@ -116,7 +116,7 @@ const leftDrawerOrg = ({ ) : ( -